package org.demo.szml.loggingservice.listener;

import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.demo.szml.eventtype.event.BaseEvent;
import org.demo.szml.eventtype.event.logging.LoggingEvent;
import org.demo.szml.eventtype.router.logging.LoggingEventRouter;
import org.demo.szml.loggingservice.service.ILoggingService;
import org.springframework.stereotype.Component;

/**
 * @description: 日志相关消息消费者
 * @date: 2025/6/16 14:59
 * @version: 1.0
 */
@Component
@RocketMQMessageListener(topic = LoggingEventRouter.LOGGING_EVENT_TOPIC, consumerGroup = LoggingEventRouter.LOGGING_CONSUMER_GROUP,maxReconsumeTimes = 3)
public class LoggingMessageConsumer implements RocketMQListener<BaseEvent.EventMessage<LoggingEvent.LoggingEventInfo>> {

    private final ILoggingService loggingService;

    public LoggingMessageConsumer(ILoggingService loggingService){
        this.loggingService = loggingService;
    }

    @Override
    public void onMessage(BaseEvent.EventMessage<LoggingEvent.LoggingEventInfo> loggingEventInfoEventMessage) {
        LoggingEvent.LoggingEventInfo data = loggingEventInfoEventMessage.getData();
        System.out.println(1);
        loggingService.saveOperationLog(data);
    }
}
